﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using SmarterCharger.App.ViewModel;

namespace SmarterCharger.App.Views
{
    public partial class EditSettingsPage : PhoneApplicationPage
    {
        private EditSettingsViewModel ViewModel
        {
            get { return DataContext as EditSettingsViewModel; }
            set { DataContext = value; }
        }

        public EditSettingsPage()
        {
            InitializeComponent();

            ViewModel = ContainerInitializer.Get<EditSettingsViewModel>();
        }

        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            AnimateScreen();
            ViewModel.LoadData();
        }

        protected override void OnNavigatedFrom(NavigationEventArgs e)
        {
            ViewModel.SaveData();
        }

        private void AnimateScreen()
        {
            var slideRight = new SlideTransition { Mode = SlideTransitionMode.SlideRightFadeIn };
            var plugPanelTransition = slideRight.GetTransition(PlugPanel);
            plugPanelTransition.Completed += delegate { plugPanelTransition.Stop(); };
            plugPanelTransition.Begin();

            var slideLeft = new SlideTransition { Mode = SlideTransitionMode.SlideLeftFadeIn };
            var chargeLimitPanelTransition = slideLeft.GetTransition(ChargeLimitPanel);
            chargeLimitPanelTransition.Completed += delegate { chargeLimitPanelTransition.Stop(); };
            chargeLimitPanelTransition.Begin();
        }
    }
}